import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  // 标签导航刷新路由
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    redirect: '/login'
  },
  // 教师端
  {
    path: '/teacher/dashboard',
    component: Layout,
    meta: { roles: ['teacher'] },
    children: [{
      path: 'index',
      name: 'Dashboard',
      component: () => import('@/views/teacher/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard', affix: true }
    }]
  },
  {
    path: '/teacher/info',
    component: Layout,
    meta: {
      roles: ['teacher']
    },
    children: [
      {
        path: 'index',
        name: 'Info',
        component: () => import('@/views/teacher/info/index.vue'),
        meta: {
          title: '个人信息管理',
          icon: 'el-icon-user-solid'
        }
      }
    ]
  },
  {
    path: '/teacher/course',
    component: Layout,
    name: 'Course',
    meta: {
      title: '课题管理',
      icon: 'el-icon-notebook-2',
      roles: ['teacher']
    },
    children: [
      {
        path: 'group',
        name: 'Group',
        component: () => import('@/views/teacher/course/group/index'),
        meta: { title: '分组管理', icon: 'el-icon-s-custom' }
      },
      {
        path: 'infoList',
        name: 'infolist',
      
        component: () => import('@/views/teacher/course/group/infoList'),
        meta: { title: '分组详情', icon: 'el-icon-s-custom' },
        hidden:true
      },
      {
        path: 'input',
        name: 'Input',
        component: () => import('@/views/teacher/course/input/index'),
        meta: { title: '课题录入', icon: 'el-icon-upload2' }
      },
      {
        path: 'edit/:subjectId',
        name: 'edit',
        component: () => import('@/views/teacher/course/input/edit'),
        
        hidden: true,
        //
        
      },
      {
        path: 'add',
        name: 'add',
        component: () => import('@/views/teacher/course/input/add'),
        
        hidden: true,
        meta: { title: '添加课题', icon: 'el-icon-upload2' }
        //
        
      },
      {
        path: 'look',
        name: 'Look',
        component: () => import('@/views/teacher/course/look/index'),
        meta: { title: '选题查看', icon: 'el-icon-view' }
      }
    ]
  },
  {
    path: '/teacher/score',
    component: Layout,
    name: 'Score',
    meta: {
      title: '成绩管理',
      icon: 'el-icon-set-up',
      roles: ['teacher']
    },
    children: [
      {
        path: 'appraise',
        name: 'Appraise',
        component: () => import('@/views/teacher/score/appraise/index'),
        meta: { title: '成绩评定', icon: 'el-icon-edit-outline' }
      },
      {
        path: 'attendance',
        name: 'Attendance',
        component: () => import('@/views/teacher/score/attendance/index'),
        meta: { title: '出勤管理', icon: 'el-icon-bicycle' }
      },
      {
        path: 'gain',
        name: 'Gain',
        component: () => import('@/views/teacher/score/gain/index'),
        meta: { title: '成果查看', icon: 'el-icon-medal-1' }
      }
    ]
  },
  // 学生端
  {
    path: '/student/dashboard',
    component: Layout,
    meta: { roles: ['student'] },
    children: [{
      path: 'index',
      name: 'Dashboard',
      component: () => import('@/views/student/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard', affix: true }
    }]
  },
  {
    path: '/student/info',
    component: Layout,
    meta: { roles: ['student'] },
    children: [
      {
        path: 'index',
        name: 'Info',
        component: () => import('@/views/student/info/index'),
        meta: {
          title: '个人信息管理',
          icon: 'el-icon-user-solid'
        }
      }
    ]
  },
  {
    path: '/student/course',
    component: Layout,
    name: 'Course',
    meta: {
      title: '课题管理',
      icon: 'el-icon-notebook-2',
      roles: ['student']
    },
    children: [
      {
        path: 'choice',
        name: 'Choice',
        component: () => import('@/views/student/course/choice/index'),
        meta: { title: '课题选择', icon: 'el-icon-s-custom' }
      },
      {
        path: 'group',
        name: 'Group',
        component: () => import('@/views/student/course/group/index'),
        meta: { title: '选择组', icon: 'el-icon-upload2' }
      }
    ]
  },
  {
    path: '/student/score',
    component: Layout,
    name: 'Score',
    meta: {
      title: '成绩管理',
      icon: 'el-icon-set-up',
      roles: ['student']
    },
    children: [
      {
        path: 'assess',
        name: 'Assess',
        component: () => import('@/views/student/score/assess/index'),
        meta: { title: '自我评价', icon: 'el-icon-edit-outline' }
      },
      {
        path: 'sign',
        name: 'Sign',
        component: () => import('@/views/student/score/sign/index'),
        meta: { title: '签到', icon: 'el-icon-bicycle' }
      },
      {
        path: 'gain',
        name: 'Gain',
        component: () => import('@/views/student/score/gain/index'),
        meta: { title: '课程设计成果上传', icon: 'el-icon-medal-1' }
      }
    ]
  },
  // 管理员端
  {
    path: '/admin/dashboard',
    component: Layout,
    meta: { roles: ['admin'] },
    children: [{
      path: 'index',
      name: 'Dashboard',
      component: () => import('@/views/admin/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard', affix: true }
    }]
  },
  {
    path: '/admin/info',
    component: Layout,
    meta: { roles: ['admin'] },
    children: [
      {
        path: 'index',
        name: 'Info',
        component: () => import('@/views/admin/info/index'),
        meta: {
          title: '个人信息管理',
          icon: 'el-icon-user-solid'
        }
      }
    ]
  },
  {
    path: '/admin/studentInfo',
    component: Layout,
    meta: { roles: ['admin'] },
    children: [
      {
        path: 'index',
        name: 'StudentInfo',
        component: () => import('@/views/admin/studentInfo/index'),
        meta: {
          title: '学生信息管理',
          icon: 'el-icon-s-custom'
        }
      }
    ]
  },
  {
    path: '/admin/teacherInfo',
    component: Layout,
    meta: { roles: ['admin'] },
    children: [
      {
        path: 'index',
        name: 'TeacherInfo',
        component: () => import('@/views/admin/teacherInfo/index'),
        meta: {
          title: '教师信息管理',
          icon: 'el-icon-user'
        }
      }
    ]
  },
  {
    path: '/admin/course',
    component: Layout,
    meta: { roles: ['admin'] },
    children: [
      {
        path: 'index',
        name: 'Course',
        component: () => import('@/views/admin/course/index'),
        meta: {
          title: '课程管理',
          icon: 'el-icon-coin'
        }
      }
    ]
  },
  {
    path: '/admin/arrangement',
    component: Layout,
    meta: { roles: ['admin'] },
    children: [
      {
        path: 'index',
        name: 'Arrangement',
        component: () => import('@/views/admin/arrangement/index'),
        meta: {
          title: '排课管理',
          icon: 'el-icon-date'
        }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
